home *** CD-ROM | disk | FTP | other *** search
- surface
- funkyfade(
- float frequency = 5,
- pbm = 0.5,
- pw = 0.5,
- wRingscale= 10,
- wKa = 1.,
- wKd = 1.,
- wKs = 0.3,
- wRoughness = 0.1;
-
- /* wood stuff */
- color wLightwood = color (0.3, 0.12, 0.03),
- wDarkwood = color (0.05, 0.01, 0.005);
- /* blue marble stuff */
- float bmKd = 1.,
- bmKa = 1.,
- bmKs = 0.3,
- bmRoughness = .1,
- bmTxtscale = 1;
-
- color bmSpecularcolor = color (0.0, 1.0, 1.0);
-
- )
- {
- float smod = mod(s*frequency,1),
- tmod = mod(t*frequency,1);
-
- point NN;
- float y, z, r;
- float sum = 0;
- float i, freq = 7.0;
- color bmCi, wCi;
-
- point PP; /* scaled point in shader space */
- float csp; /* color spline parameter */
- point Nf; /* forward-facing normal */
- point V; /* for specular() */
- float pixelsize, twice, scale, weight, turbulence;
-
- /* do blue_marble */
- {
- /* Obtain a forward-facing normal for lighting calculations. */
- Nf = faceforward( normalize(N), I);
- V = normalize(-I);
-
- /*
- * Compute "turbulence" a la [PERLIN85]. Turbulence is a sum of
- * "noise" components with a "fractal" 1/f power spectrum. It gives the
- * visual impression of turbulent fluid flow (for example, as in the
- * formation of blue_marble from molten color splines!). Use the
- * surface element area in texture space to control the number of
- * noise components so that the frequency content is appropriate
- * to the scale. This prevents aliasing of the texture.
- */
- PP = transform("shader", P) * bmTxtscale;
- pixelsize = sqrt(area(PP));
- twice = 2 * pixelsize;
- turbulence = 0;
- for (scale = 1; scale > twice; scale /= 2)
- turbulence += scale * noise(PP/scale);
-
- /* Gradual fade out of highest-frequency component near limit */
- if (scale > pixelsize) {
- weight = (scale / pixelsize) - 1;
- weight = clamp(weight, 0, 1);
- turbulence += weight * scale * noise(PP/scale);
- }
-
- /*
- * Magnify the upper part of the turbulence range 0.75:1
- * to fill the range 0:1 and use it as the parameter of
- * a color spline through various shades of blue.
- */
- csp = clamp(4 * turbulence - 3, 0, 1);
- bmCi = color spline(csp,
- color (0.25, 0.25, 0.35), /* pale blue */
- color (0.25, 0.25, 0.35), /* pale blue */
- color (0.20, 0.20, 0.30), /* medium blue */
- color (0.20, 0.20, 0.30), /* medium blue */
- color (0.20, 0.20, 0.30), /* medium blue */
- color (0.25, 0.25, 0.35), /* pale blue */
- color (0.25, 0.25, 0.35), /* pale blue */
- color (0.15, 0.15, 0.26), /* medium dark blue */
- color (0.15, 0.15, 0.26), /* medium dark blue */
- color (0.10, 0.10, 0.20), /* dark blue */
- color (0.10, 0.10, 0.20), /* dark blue */
- color (0.25, 0.25, 0.35), /* pale blue */
- color (0.10, 0.10, 0.20) /* dark blue */
- );
-
- /* Multiply this color by the diffusely reflected light. */
- bmCi *= bmKa*ambient() + bmKd*diffuse(Nf);
-
- /* Adjust for opacity. */
- Oi = Os;
- bmCi = bmCi * Oi;
-
- /* Add in specular highlights. */
- bmCi += bmSpecularcolor * bmKs * specular(Nf,V,bmRoughness);
- }
-
- /* do wood */
- {
- /*
- * Compute the forward-facing normal NN and the vector
- * toward the ray origin V, both normalized.
- * These vectors are used by "specular" and "diffuse". */
- NN = faceforward(normalize(N),I);
- V = -normalize(I);
-
- /* put point in shader space and perturb it to add irregularity */
- PP = transform("shader", P);
- PP += noise(PP);
-
- /* compute radial distance r from PP to axis of "tree" */
- y = ycomp(PP);
- z = zcomp(PP);
- r = sqrt(y*y + z*z);
-
- /* map radial distance r into ring position [0,1] */
- r *= wRingscale;
- r += abs(noise(r));
- r -= floor(r); /* == mod(r,1) */
-
- /* use ring position r to select wood color */
- r = smoothstep(0, 0.8, r) - smoothstep(0.83, 1.0, r);
- wCi = mix(wLightwood, wDarkwood, r);
-
- /* shade using r to vary shininess */
- Oi = Os;
- wCi = Oi * wCi * (wKa * ambient() + wKd * diffuse(NN))
- + (0.3*r + 0.7) * wKs * specular(NN, V, wRoughness);
- }
-
- /* combine the two */
- if(smod<0.5)
- Ci=(wCi*smod*2) + (bmCi*(1.0-(smod*2)));
- else Ci=(wCi*(2.0-smod*2)) + (bmCi*(smod*2 -1));
- }
-
-
-